﻿<form id="form1" method="post">
    @Html.AntiForgeryToken()
    <table cellpadding="0" cellspacing="1" border="0" style="width:100%; margin:0 auto;">
        <tr>
            <td style="width:48%; vertical-align:top;">
                <div style="width:100%; margin:0 auto;">
                    <div class="toolbar" style="margin-top:0; border-top:none 0; position:fixed; top:0; left:0; right:0; margin-left:auto; z-index:999; width:100%; margin-right:auto;">
                        <a href="javascript:void(0);" onclick="saveSet(this);">
                            <i class="fa fa-save"></i><label>保存设置</label>
                        </a>
                        <a href="javascript:void(0);" onclick="saveSort(this);">
                            <i class="fa fa-road"></i><label>保存排序</label>
                        </a>
                    </div>
                    <table id="treeTable1" style="width:100%; margin-top:37px;" class="listtable">
                        <thead>
                            <tr>
                                <th style="width:26%;">标题</th>
                                <th style="width:7%;">图标</th>
                                <th style="width:7%; text-align:center"><input type="checkbox" id="checkall" onclick="$('input[type=\'checkbox\']').prop('checked', this.checked);" /></th>
                            </tr>
                        </thead>
                        <tbody>
                            @Html.Raw(ViewData["menuhtml"])
                        </tbody>
                    </table>
                </div>
            </td>
            <td></td>
            <td style="width:48%; vertical-align:top; padding-top:5px;">
                <div style="width:82%; margin:40px auto 0  auto; height:auto;" id="sortdiv">
                    @foreach (var shortcut in (List<RoadFlow.Model.UserShortcut>)ViewData["shortcuts"])
                    {
                        var menuModel = new RoadFlow.Business.Menu().Get(shortcut.MenuId);
                        if (menuModel == null)
                        {
                            continue;
                        }
                        <ul class="sortul">
                            <input type="hidden" value="@shortcut.Id" name="sort" />
                            @menuModel.Title
                        </ul>
                    }
                </div>
            </td>
        </tr>
    </table>
</form>
<script type="text/javascript">
    var json = @Html.Raw(ViewData["shortcutJson"]);
    $(function () {
        new RoadUI.DragSort($("#sortdiv"));
        new RoadUI.TreeTable().init({ id: "treeTable1" });
        $("#treeTable1 tbody tr").each(function () {
            $("td:last", $(this)).remove();
            $("td:last", $(this)).remove();
        });
        for (var i = 0; i < json.length; i++) {
            $("input[value='" + json[i].MenuId.toUpperCase() + "']").prop("checked", true);
        }
    });

    function appboxclick(box) {
        return;
    }
    function saveSet(a) {
        var f = document.forms[0];
        if (new RoadUI.Validate().validateForm(f)) {
            var o = RoadUI.Core.serializeForm($(f));
            $(a).unbind("click");
            $.ajax({
                url: "SaveShortcut@(Html.Raw(ViewData["queryString"]))", data: o, type: "post", success: function (text) {
                    if (RoadUI.Core.checkLogin(text, false)) {
                        alert(text);
                        window.location = window.location;
                    }
                    //$(but).prop("disabled", false);
                }
            });
        }
    }
    function saveSort(a) {
        var f = document.forms[0];
        if (new RoadUI.Validate().validateForm(f)) {
            var o = RoadUI.Core.serializeForm($(f));
            $(a).unbind("click");
            $.ajax({
                url: "SaveShortcutSort@(Html.Raw(ViewData["queryString"]))", data: o, type: "post", success: function (text) {
                    if (RoadUI.Core.checkLogin(text, false)) {
                        alert(text);
                        window.location = window.location;
                    }
                    //$(but).prop("disabled", false);
                }
            });
        }
    }
</script>
